﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PoJun.Tools
{
    /// <summary>
    /// GUID帮助类
    /// </summary>
    public class GUDIHelper
    {
        /// <summary>
        /// 取得6位的GUID
        /// </summary>
        /// <returns></returns>
        public static string GetBy6()
        {
            return Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace("/", "_").Replace("+", "-").Substring(0, 6);
        }

        /// <summary>
        /// 取得16位的GUID
        /// </summary>
        /// <returns></returns>
        public static string GetBy16()
        {
            long i = 1;
            foreach (byte b in Guid.NewGuid().ToByteArray())
            {
                i *= ((int)b + 1);
            }
            return string.Format("{0:x}", i - DateTime.Now.Ticks);
        }

        /// <summary>
        /// 取得22位的GUID
        /// </summary>
        /// <returns></returns>
        public static string GetBy22()
        {
            return Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace("/", "_").Replace("+", "-");
        }

        /// <summary>
        /// 取得32位的GUID
        /// </summary>
        /// <returns></returns>
        public static string GetBy32()
        {
            return System.Guid.NewGuid().ToString("N");
        }
    }
}
